﻿using System;
class ConvertDirectlyBinToHex
{
    static string BinaryToHexadecimal(string biNumber)
    {
        string res = string.Empty;
        for (int i = 0; i <= (biNumber.Length % 4); i++)
        {
            biNumber = "0" + biNumber;
        }
        for (int j = 0; j <= (biNumber.Length - 4); j += 4)
        {
            switch (biNumber.Substring(j, 4))
            {
                case "0000":
                    { res = res + "0"; break; }
                case "0001":
                    { res = res + "1"; break; }
                case "0010":
                    { res = res + "2"; break; }
                case "0011":
                    { res = res + "3"; break; }
                case "0100":
                    { res = res + "4"; break; }
                case "0101":
                    { res = res + "5"; break; }
                case "0110":
                    { res = res + "6"; break; }
                case "0111":
                    { res = res + "7"; break; }
                case "1000":
                    { res = res + "8"; break; }
                case "1001":
                    { res = res + "9"; break; }
                case "1010":
                    { res = res + "A"; break; }
                case "1011":
                    { res = res + "B"; break; }
                case "1100":
                    { res = res + "C"; break; }
                case "1101":
                    { res = res + "D"; break; }
                case "1110":
                    { res = res + "E"; break; }
                case "1111":
                    { res = res + "F"; break; }
                default:
                    { break; }
            }
        }
        return res;
    }
    static void Main()
    {
        Console.Write("please input Bin number: ");
        string binNumber = Console.ReadLine();
        string result = BinaryToHexadecimal(binNumber);
        Console.Write("the hexadecimal representation of {0}, is: ",binNumber);
        Console.WriteLine(result);
        Console.ReadLine();
    }
}

